<?php

declare(strict_types=1);
/**
 * @copyright 深圳市易果网络科技有限公司
 * @version 1.0.0
 * @link https://dayiguo.com
 */

namespace App\Service\Business;

use App\Constants\Constants;
use App\Dao\RecommendDao;
use App\Dao\UserDao;
use App\Kernel\Util\UserJwtInstance;
use App\Service\Service;
use App\Middleware\Business\BusinessMiddleware;

use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Middleware;

/**
 * 推荐返点
 *
 * @Middleware(BusinessMiddleware::class)
 * @author 李想(928674263@qq.com)
 * @package App\Service\Business
 */
class RecommendService extends Service
{
    /**
     * @Inject
     *
     * @var RecommendDao
     */
    public $dao;

    /**
     * @Inject
     *
     * @var UserDao
     */
    public $User_dao;

    /**
     * 获取用户身份信息
     *
     * @return array
     */
    public function getUserInfo()
    {
        $user = UserJwtInstance::instance()->build()->getUser();

        $return_data['identity_code'] = $user['identity_code'];
        $return_data['group_name'] = $user['group']['name'];
        $return_data['group_id'] = $user['group']['id'];

        return $return_data;
    }

    /**
     * @return \App\Model\User|null
     */
    public function getShareInfo()
    {
        $user = UserJwtInstance::instance()->build()->getUser();
        $business = $user->business;

        return $business;
    }

    /**
     * 统计用户分享的会员数量
     *
     * @return mixed
     */
    public function countMember()
    {
        $user = UserJwtInstance::instance()->build()->getUser();

        $condition = [
            'parent_id' => $user->id,
            'group_id' => $this->User_dao::USER_MEMBER,
        ];

        $result['count_num'] = $this->User_dao->count( $condition );

        return $result;
    }

    /**
     * 统计用户分享的会员数量
     *
     * @return mixed
     */
    public function countBusiness()
    {
        $user = UserJwtInstance::instance()->build()->getUser();

        $condition = [
            'parent_id' => $user->id,
            'group_id' => $this->User_dao::USER_BUSINESS,
        ];

        $result['count_num'] = $this->User_dao->count( $condition );

        return $result;
    }

    //统计用户分享的会员为他带来积分收益的明细列表
    public function getIntegralByMember()
    {
        $user = UserJwtInstance::instance()->build()->getUser();

        $condition = [
            'parent_id' => $user->id,
            'group_id' => $this->User_dao::USER_MEMBER,
        ];

        $sort = 'id desc';

        $result = $this->User_dao->getIntegralByMember( $condition ,$sort );

        return $result;
    }

}